
Page({

  /**
   * 页面的初始数据
   */
  data: {
    question: 0,
    id:"",
    answer:""

  },


 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var i = decodeURIComponent(options.id);
    var item = JSON.parse(i);
    var that = this;
    that.setData({
      question: item
    })
  },

  formSubmit: function (e) {
    var that = this;
    var id = e.detail.value.id;
   
    var answer = e.detail.value.answer;
    //console.log(id+answer);
    wx.showModal({
      title: '提示',
      content: '确定要提交吗?',

      success(res) {
      if(res.confirm){
        wx.request({
          url: "http://localhost:8080/exam/wxanswer",
          data: {
            'id': id,
            'answer':answer
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res);
            console.log(res.data);
            console.log(res.data.answer);
            if (res.data.answer == answer) {

                  wx.request({
                   
                    url: "http://localhost:8080/exam/wxExam_Type",
                    data: {
                      'question_type': "填空题"
                    },
                    method: "post",

                    header: {
                      // 'content-type': 'application/x-www-form-urlencoded'
                      'content-type': 'application/x-www-form-urlencoded'
                    },
                    success: function (res) {
                      console.log("已执行。。")
                      console.log(res.data.question);
                      if (res.data.result != null) {
                        console.log(res.data.result);
                        console.log(res.data.result.question_type);
                        console.log(res.data.result.id);

                        var idd = JSON.stringify(res.data.result);
                        var id = encodeURIComponent(idd);
                        console.log(idd);
                        if (res.data.result.question_type == '选择题') {
                          wx.navigateTo({

                            url: '../test1/test1?id=' + id

                          })
                        }
                        else if (res.data.result.question_type == '判断题') {
                          wx.navigateTo({

                            url: '../test2/test2?id=' + id

                          })
                        }
                        else if (res.data.result.question_type == '填空题') {
                          wx.navigateTo({

                            url: '../test3/test3?id=' + id

                          })
                        }


                      }
                    }
                  })
}
          
    else{
             
                wx.switchTab({
                  title: '答题结束',
                url: '../home/home'
                });


    }      
          

          
          }

        })

      }
       else if(res.cancel) {
    console.log('用户点击取消')
   }
      }


    })



    
  }












})